Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: Check token and ACLs on request #19138

Merged
merged 3 commits into from
Feb 10, 2023
Merged

Conversation

swenson
Copy link
Contributor

@swenson swenson commented Feb 10, 2023

This checks the request against the read permission for sys/events/subscribe/{eventType} on the initial subscribe.

Future work includes moving this to its own verb (subscribe) and periodically rechecking the request.

Tested locally by minting a token with the wrong permissions and verifying that they are rejected as expected, and that they work if the policy is adjusted to sys/event/subscribe/* (or the specific topic name) with read permissions.

I had to change the core.checkToken() to be publicly accessible, as it seems like the easiest way to check the token on the logical.Request against all relevant policies, but without going into all of the complex logic further in handleLogical().

This checks the request against the `read` permission for
`sys/events/subscribe/{eventType}` on the initial subscribe.

Future work includes moving this to its own verb (`subscribe`)
and periodically rechecking the request.

Tested locally by minting a token with the wrong permissions
and verifying that they are rejected as expected, and that
they work if the policy is adjusted to `sys/event/subscribe/*`
(or the specific topic name) with `read` permissions.

I had to change the `core.checkToken()` to be publicly accessible,
as it seems like the easiest way to check the token on the
`logical.Request` against all relevant policies, but without
going into all of the complex logic further in `handleLogical()`.
@swenson swenson added this to the 1.13.0-rc1 milestone Feb 10, 2023
Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some nits 👍

@@ -53,7 +63,9 @@ func TestEventsSubscribe(t *testing.T) {
t.Cleanup(cancelFunc)

wsAddr := strings.Replace(addr, "http", "ws", 1)
conn, _, err := websocket.Dial(ctx, wsAddr+"/v1/sys/events/subscribe/"+eventType+"?json=true", nil)
conn, _, err := websocket.Dial(ctx, wsAddr+"/v1/sys/events/subscribe/"+eventType+"?json=true", &websocket.DialOptions{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add a Dial just above that doesn't include the token, and check that we get an error + 403 status code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

http/events.go Outdated Show resolved Hide resolved
respondError(w, http.StatusUnauthorized, fmt.Errorf("permission denied or invalid token"))
return
}
respondError(w, http.StatusInternalServerError, fmt.Errorf("error validating token"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably log the error here?

Christopher Swenson and others added 2 commits February 10, 2023 12:19
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants